﻿using Macro_stone.DtoModel.FileManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemCenterSoa.DtoModel.SystemManager;
using SystemCenterSoa.IRepository.SystemManager;
using SystemCenterSoa.PoModel.SystemManager;
using SystemCenterSoa.Repository.CommonLib;

namespace SystemCenterSoa.Repository.SystemManager
{
    public class QualificationRepository : BaseRepository, IQualificationRepository
    {
        public QualificationRepository(SystemCenterDbSoaContext systemCenterDbSoaContext) : base(systemCenterDbSoaContext)
        {
        }
        /// <summary>
        /// 分页条件查询
        /// </summary>
        /// <param name="quaName"></param>
        /// <param name="queLevel"></param>
        /// <param name="quaAnnualAuditDate"></param>
        /// <returns></returns>
        public List<QualificationPo> GetQualificationList(string quaName, string queLevel, DateTime? quaAnnualAuditDate)
        {
            //获取全部数据
            var query = _systemCenterDbSoaContext.Qualifications.AsQueryable();
            //var query = from A in _systemCenterDbSoaContext.Qualifications
            //            join B in _systemCenterDbSoaContext.FileUpLoadResults
            //            on A.qua_id equals B.qua_id
            //            select new QualificationDto()
            //            {
            //                qua_id = A.qua_id,
            //                qua_name = A.qua_name,
            //                qua_start_date = A.qua_start_date,
            //                qua_end_date = A.qua_end_date,
            //                qua_annual_audit_date = A.qua_annual_audit_date,
            //                qua_content = A.qua_content,
            //                que_level = A.que_level,
            //                FileNewPath = B.FileNewPath,
            //                FileNewName = B.FileNewName,
            //                FileType = B.FileType,
            //                FileOldName = B.FileOldName,
            //                FileSize = B.FileSize,
            //                UpLoadDate = B.UpLoadDate,
            //                IsUpload = B.IsUpload,
            //                Mess = B.Mess,
            //            };
            if (!string.IsNullOrWhiteSpace(quaName))
            {
                query = query.Where(t => t.qua_name.Contains(quaName));
            }
            if (!string.IsNullOrWhiteSpace(queLevel))
            {
                query = query.Where(t => t.que_level == queLevel);
            }
            if (quaAnnualAuditDate!=null)
            {
                query = query.Where(t => t.qua_annual_audit_date == quaAnnualAuditDate);
            }
            return query.OrderBy(t => t.qua_id).ToList();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Qualification"></param>
        /// <returns></returns>
        public bool GetQualificationAdd(QualificationPo Qualification)
        {
            _systemCenterDbSoaContext.Qualifications.Add(Qualification);
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public bool GetQualificationDel(string ids)
        {
            var ArrId = ids.Split(',');
            foreach (var item in ArrId)
            {
                int id = Convert.ToInt32(item);
                _systemCenterDbSoaContext.Qualifications.Remove(_systemCenterDbSoaContext.Qualifications.Find(id));
            }
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public QualificationPo GetQualificationFan(int id)
        {
            return _systemCenterDbSoaContext.Qualifications.Find(id);
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="Qualification"></param>
        /// <returns></returns>
        public bool GetQualificationUpdate(QualificationPo Qualification)
        {
            _systemCenterDbSoaContext.Entry(Qualification).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges() > 0;
        }
    }
}
